<template>
  <Footer v-if="getShowLayoutFooter" ref="footerRef" :class="prefixCls">
    <div :class="`${prefixCls}__links`">
      <a @click="openWindow(SITE_URL)">外包咨询</a>

      <GithubFilled :class="`${prefixCls}__github`" @click="openWindow(GITHUB_URL)" />

      <a @click="openWindow(DOC_URL)">{{ t('layout.footer.onlineDocument') }}</a>
    </div>
    <div>Copyright &copy;2023 {{ SITE_TITLE }}</div>
  </Footer>
</template>

<script lang="ts" setup name="LayoutFooter">
import { GithubFilled } from '@ant-design/icons-vue';
import { Layout } from 'ant-design-vue';
import { computed, ref, unref } from 'vue';
import { useRouter } from 'vue-router';

import { useRootSetting } from '@/hooks/setting/useRootSetting';
import { useDesign } from '@/hooks/web/useDesign';
import { useI18n } from '@/hooks/web/useI18n';
import { DOC_URL, GITHUB_URL, SITE_URL } from '@/settings/siteSetting';
import { openWindow } from '@/utils';

import { useLayoutHeight } from '../content/useContentViewHeight';

const SITE_TITLE = ref(import.meta.env.VITE_GLOB_APP_TITLE);

const Footer = Layout.Footer;

const { t } = useI18n();
const { getShowFooter } = useRootSetting();
const { currentRoute } = useRouter();
const { prefixCls } = useDesign('layout-footer');

const footerRef = ref<ComponentRef>(null);
const { setFooterHeight } = useLayoutHeight();

const getShowLayoutFooter = computed(() => {
  if (unref(getShowFooter)) {
    const footerEl = unref(footerRef)?.$el;
    setFooterHeight(footerEl?.offsetHeight || 0);
  } else {
    setFooterHeight(0);
  }
  return unref(getShowFooter) && !unref(currentRoute).meta?.hiddenFooter;
});
</script>
<style lang="less" scoped>
@prefix-cls: ~'@{namespace}-layout-footer';

@normal-color: rgba(0, 0, 0, 0.45);

@hover-color: rgba(0, 0, 0, 0.85);

.@{prefix-cls} {
  color: @normal-color;
  text-align: center;

  &__links {
    margin-bottom: 8px;

    a {
      color: @normal-color;

      &:hover {
        color: @hover-color;
      }
    }
  }

  &__github {
    margin: 0 30px;

    &:hover {
      color: @hover-color;
    }
  }
}
</style>
